#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <map> 
#include <unordered_set>

#define flr(x, l, r) for (int x = l; x <= r; ++x)
#define frl(x, r, l) for (int x = r; x >= l; --x)
#define fmp(x, t) for (int x = h[t]; ~x; x = ne[x])
#define LL long long
#define mt memset
#define my memcpy
#define szf sizeof
#define INF 0x3f3f3f3f
#define in(x) scanf("%d", &x)
#define out(x) printf("%d", x)
#define inll(x) scanf("%lld", &x)
#define outll(x) printf("%lld", x)
#define pn printf("\n")
#define con continue
#define bk break
#define vc vector
#define pb push_back
#define sz size
#define PII pair<int, int>
#define x first
#define y second
#define P_q priority_queue
#define ft front
#define pf push_front
#define popf pop_front
#define it insert
#define ct count

using namespace std;

const int N = 100010, M = 2000010;

int n, m, mod;
int h[N], hs[N], e[M], ne[M], idx;
int dfn[N], low[N], timestamp;
int scc_cnt, Size[N], id[N];
int stk[N], top;
bool in_stk[N];
int f[N], g[N];

void add(int h[], int a, int b) {
    e[idx] = b, ne[idx] = h[a], h[a] = idx ++ ;
}

void tarjan(int u) {
    dfn[u] = low[u] = ++ timestamp;
    stk[ ++ top] = u, in_stk[u] = true;
    
    fmp (i, u) {
        int j = e[i];
        
        if (!dfn[j]) {
            tarjan(j);
            low[u] = min(low[u], low[j]);
        }
        else if (in_stk[j]) low[u] = min(low[u], dfn[j]);
    }
    
    if (dfn[u] == low[u]) {
        ++ scc_cnt;
        int y;
        do {
            y = stk[top -- ];
            in_stk[y] = false;
            id[y] = scc_cnt;
            Size[scc_cnt] ++ ;
        } while (y != u);
    }
}

int main() {
	in(n), in(m), in(mod);
	
	mt(h, -1, szf h), mt(hs, -1, szf hs);
	while (m -- ) {
	    int a, b;
	    in(a), in(b);
	    add(h, a, b);
	}
	
	flr (i, 1, n)
	    if (!dfn[i])
	        tarjan(i);
	
	unordered_set<LL> S;
	flr (i, 1, n)
	    fmp (j, i) {
	        int k = e[j];
	        int a = id[i], b = id[k];
	        LL hash = a * 1000000ll + b;
	        if (a != b && !S.count(hash)) {
	            add(hs, a, b);
	            S.insert(hash);
	        }
	    }
	
	frl (i, scc_cnt, 1) {
	    if (!f[i]) {
	        f[i] = Size[i];
	        g[i] = 1;
	    }
	    
	    for (int j = hs[i]; ~j; j = ne[j]) {
	        int k = e[j];
	        if (f[k] < f[i] + Size[k]) {
	            f[k] = f[i] + Size[k];
	            g[k] = g[i];
	        }
	        else if (f[k] == f[i] + Size[k])
	            g[k] = (g[k] + g[i]) % mod;
	    }
	}
	
	int num1 = 0, num2 = 0;
	flr (i, 1, scc_cnt) {
	    if (f[i] > num1)
	        num1 = f[i], num2 = g[i];
	    else if (f[i] == num1) num2 = (num2 + g[i]) % mod;
	}
	
	out(num1), pn;
	out(num2), pn;
	
    return 0;
}